package com.example.conusmer.controller

import com.example.conusmer.service.RemarkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.*

@RestController
@RequestMapping("/api/remark")
class RemarkController  {
    @Autowired
    lateinit var remarkService:RemarkService
    @GetMapping("/{key}")
    fun getValue(@PathVariable key: String): ResponseEntity<String?> = ResponseEntity.ok(remarkService.findFromRedis(key))

    @PostMapping
    fun setValue(@RequestBody map: Map<String, String>): ResponseEntity<Void> {
        map.forEach { (k, v) -> remarkService.saveToRedis(k, v) }
        return ResponseEntity.noContent().build()
    }

    @DeleteMapping("/{key}")
    fun deleteValue(@PathVariable key: String): ResponseEntity<Void> {
        remarkService.deleteFromRedis(key)
        return ResponseEntity.noContent().build()
    }
}